﻿<template>
    <div class="esOrder-container">
        <el-dialog v-model="state.isShowDialog" draggable width="769px">
            <template #header>
                <div style="color: #fff">
                    <el-icon size="16" style="margin-right: 3px; display: inline; vertical-align: middle">
                        <ele-Edit/>
                    </el-icon>
                    <span> {{ props.title }} </span>
                </div>
            </template>
            <el-form :model="state.ruleForm" ref="ruleFormRef" size="default" label-width="80px">
                <el-row :gutter="35">
                    <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
                        <el-form-item label="商户名称" prop="merchantName">
                            <el-input :value="state.ruleForm.merchantName" placeholder="请输入商户ID" class="w100"
                                      readonly/>
                        </el-form-item>
                    </el-col>
                    <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
                        <el-form-item label="渠道名称" prop="channelName">
                            <el-input :value="state.ruleForm.channelName" placeholder="请输入渠道ID" class="w100"
                                      readonly/>
                        </el-form-item>
                    </el-col>
                    <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
                        <el-form-item label="产品名称" prop="productId">
                            <el-input :value="state.ruleForm.productName" placeholder="请输入产品ID" class="w100"
                                      readonly/>
                        </el-form-item>
                    </el-col>
                    <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
                        <el-form-item label="手机号码" prop="phone">
                            <el-input :value="state.ruleForm.phone" placeholder="请输入手机号码" class="w100" readonly/>
                        </el-form-item>
                    </el-col>
                    <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
                        <el-form-item label="省-市" prop="province">
                            <el-input
                                :value="`${state.ruleForm.province || ''}-${state.ruleForm.city ? state.ruleForm.city : ''}`"
                                placeholder="省-市" class="w100" readonly/>
                        </el-form-item>
                    </el-col>
                    <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
                        <el-form-item label="信息费" prop="informationFee">
                            <el-input :value="state.ruleForm.informationFee" placeholder="请输入信息费" class="w100"
                                      readonly/>
                        </el-form-item>
                    </el-col>
                    <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
                        <el-form-item label="商户结算" prop="merchantSettlementPrice">
                            <el-input :value="state.ruleForm.merchantSettlementPrice" placeholder="请输入商户结算价格"
                                      class="w100"
                                      clearable/>
                        </el-form-item>
                    </el-col>
                    <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
                        <el-form-item label="渠道结算" prop="channelSettlementPrice">
                            <el-input :value="state.ruleForm.channelSettlementPrice" placeholder="请输入渠道结算价格"
                                      class="w100"
                                      readonly/>
                        </el-form-item>
                    </el-col>
                    <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
                        <el-form-item label="透传数据" prop="extData">
                            <el-input :value="state.ruleForm.extData" placeholder="请输入透传数据" class="w100"
                                      readonly/>
                        </el-form-item>
                    </el-col>

                    <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
                        <el-form-item label="订单状态" prop="orderStatus">
                            <el-select v-model='state.ruleForm.orderStatus' class="w100" disabled>
                                <el-option v-for='item in optionDict.orderStatusDict' :key='item.value'
                                           :label='item.label'
                                           :value='item.value'/>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
                        <el-form-item label="是否扣除" prop="isDeduction">
                            <el-select v-model='state.ruleForm.isDeduction' class="w100" disabled>
                                <el-option v-for='item in optionDict.deductionDict' :key='item.value'
                                           :label='item.label'
                                           :value='item.value'/>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
                        <el-form-item label="请求IP" prop="requestIP">
                            <el-input :value="state.ruleForm.requestIP" placeholder="请输入请求IP" class="w100"
                                      readonly/>
                        </el-form-item>
                    </el-col>
                    <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
                        <el-form-item label="外部订单" prop="outOrderId">
                            <el-input :value="state.ruleForm.outOrderId" placeholder="请输入外部订单ID"
                                      class="w100" readonly/>
                        </el-form-item>
                    </el-col>
                    <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
                        <el-form-item label="商户订单" prop="merchantOrderId">
                            <el-input :value="state.ruleForm.merchantOrderId" placeholder="请输入商户订单ID"
                                      class="w100" readonly/>
                        </el-form-item>
                    </el-col>
                    <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
                        <el-form-item label="订单描述" prop="orderMessage">
                            <el-input :value="state.ruleForm.orderMessage" type="textarea" placeholder="请输入订单描述"
                                      class="w100" :autosize="{ minRows: 1 }" readonly/>
                        </el-form-item>
                    </el-col>
                    <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
                        <el-form-item label="备注" prop="remark">
                            <el-input :value="state.ruleForm.remark" type="textarea" placeholder="无备注" class="w100"
                                      readonly/>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
            <template #footer>
				<span class="dialog-footer">
                    <el-button @click="orderFeedback" size="default"
                               v-if="state.ruleForm.orderStatus == 1">反馈商户</el-button>
                    <el-button @click="appendChannelOrder" size="default"
                               v-if="state.ruleForm.isDeduction">渠道同步</el-button>
					<el-button type="primary" @click="closeDialog" size="default">关 闭</el-button>
				</span>
            </template>
        </el-dialog>
    </div>
</template>

<script lang="ts" setup name="editEsOrder">
import {reactive, ref} from 'vue';
import mittBus from '/@/utils/mitt';

import {EsOrder} from '/@/api/models';
import {optionDict} from "/@/const/dict";

import SysEsOrderApi from '/@/api/exocytosis/order';
import {ElMessage, ElMessageBox} from "element-plus";

// 定义变量内容
const props = defineProps({
    title: String,
});
const ruleFormRef = ref();
const state = reactive({
    isShowDialog: false,
    ruleForm: {} as EsOrder,
});

// 打开弹窗
const openDialog = (row: EsOrder) => {
    state.ruleForm = row;
    state.isShowDialog = true;
};

// 关闭弹窗
const closeDialog = () => {
    mittBus.emit('submitRefresh');
    state.isShowDialog = false;
};

// 数据回调-给渠道同步订单
const appendChannelOrder = () => {
    ElMessageBox.confirm('确定号码【' + state.ruleForm.phone + '】给渠道【' + state.ruleForm.channelName + '】同步吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
    }).then(async () => {
        await SysEsOrderApi().appendChannelOrder({esSmsInteractionId: state.ruleForm.id})
            .then((res) => {
                ElMessage.info({
                    message:'响应结果：' +  res.data
                });
            });
    }).catch(() => {
        ElMessage({
            type: 'info',
            message: '已取消'
        });
    });
};

// 订单反馈
const orderFeedback = () => {
    ElMessageBox.confirm('确定号码【' + state.ruleForm.phone + '】给产品方【' + state.ruleForm.merchantName + '】反馈吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
    }).then(async () => {
        await SysEsOrderApi().orderFeedback({esSmsInteractionId: state.ruleForm.id})
            .then((res) => {
                    ElMessage.info({
                        message:'响应结果：' +  res.data
                    });
            });
    }).catch(() => {
        ElMessage({
            type: 'info',
            message: '已取消'
        });
    });
};

// 导出对象 将属性或者函数暴露给父组件
defineExpose({openDialog});
</script>
